# Replication archive for Cross-Country Trends in Affective Polarization
## Boxell, Gentzkow, and Shapiro

------------------------------------------------------------------------------------------------------------------

## Repository Overview
The root of the directory structure contains a script called `SConstruct`. Each subfolder of `analysis/source` and `paper_slides/source` contains a script called `SConscript`. The scripts called `SConstruct` and `SConscript` can be treated as documentation on the relationships among the different objects in the archive. 

The LyX files in `paper_slides/source` can be treated as documentation on the internal names of the tables and plots in the paper within the code archive.

See ReadMe [here](https://github.com/gslab-econ/template/tree/4.1.3) for a broader overview of the repository structure and requirements.

All analysis code was originally run on Mac OS X machines using Python 2.7.

------------------------------------------------------------------------------------------------------------------

## Repository Stucture 
- `config` : initializes the environment needed for our analysis on local machines and computing clusters.

- `analysis/source`
	- `raw` : contains the raw data files used in the analysis that are included in the replication package.
	  - `codebook_map` : details the relevant variable names in the raw election surveys.
	  - `survey_list` : enumerates the election surveys we are aware of for the set of OECD countries considered.
	  - `drivers` : each subfolder contains data used to explore correlations between trends in socioeconomic factors and trends in affective polarization.
	- `prepare_data` : contains scripts to clean the data.
	- `descriptive` : contains scripts and supporting files that perform the main analysis in the paper.
 	- `lib` : contains library functions called in the analysis.
	- `externals` : where the election studies should be placed. 
	  - `wvs` : the World Values Survey data.
	  - `orig`: tree structure for raw data.

- `analysis/release/` : the location where the final analysis output is stored.
- `analysis/build/` : the location where the intermediate analysis output is stored (created by the program).

- `paper_slides`
	- `input` : contains tables that are imported to the paper.
	- `source` : contains source files for the paper.
	- `release` : contains output from directories in `paper_slides/source`.
    - `build` : contains intermediate output from directories in `paper_slides/source`.
    
## Description of Main Analysis Scripts
Our main analysis is done via code files in `analysis/source/prepare_data` and  `analysis/source/descriptive`. 

Each of these scripts may call functions or constant definitions that are stored in `analysis/source/lib`. 

Below we list all the main files used in the analysis and detail their main purpose: 

- `analysis/source/prepare_data`
	- `build.r` : takes the raw election survey data as an input, and produces a cleaned individual-level dataset.
	- `cses.r`  : takes the raw CSES data as an input, and produces a cleaned individual-level dataset.

  These two scripts use functions helpers that are located in `analysis/source/prepare_data/helpers`. 

- `analysis/source/descriptive`
	- `compute.r` : takes the cleaned individual-level datasets as inputs, and produces a country-year-level dataset of affective polarization.
	- `plot.r` : produces the main plots and tables, excluding the drivers.
	- `drivers.r` : cleans all driver data.
	- `plot_driver.r` : creates various plots used in the paper on the drivers of affective polarization
	- `anes_cses_comparison.do` : compares trends in polarization between ANES and CSES data in the US.
	- `get_supt_bands.m` : constructs the sup-t bands for inference.
	- `survey_dotplot.r` : creates a dotplot for the country-years with available election studies.

## Accessing Raw Data

Some raw data are excluded from this replication archive due to restrictions on distribution. Information on data access for interested researchers is available in the online appendix to the published paper.

After obtaining access to raw data, raw data files can be placed in `/source/externals/orig` following the tree structure in `externals_tree.md`.

------------------------------------------------------------------------------------------------------------------


